# 构建阶段
FROM golang:1.22 AS builder

WORKDIR /app

# 下载依赖
COPY go.mod go.sum ./
RUN go mod download

# 复制源码
COPY . .

# 构建应用
RUN CGO_ENABLED=0 GOOS=linux go build -o stack_service ./cmd/main.go

# 运行阶段
FROM alpine:latest

WORKDIR /root/

# 从构建阶段复制二进制文件
COPY --from=builder /app/stack_service .

# 暴露端口
EXPOSE 8082

# 启动服务
CMD ["./stack_service"]